//
//  XLDoctor
//
//  Created by longma on 2018/7/31.
//  Copyright © 2018年 XLH. All rights reserved.
//

#import "MJHelper.h"
@interface MJHelper ()

@end

@implementation MJHelper

/**
 单例
 */
+ (instancetype)shared{
    static MJHelper *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[MJHelper alloc] init];
    });
    return instance;
}

+ (void)disableThirdPartyKeyboardWithUITextField:(UITextField *)textField{
    
    [[textField rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(__kindof UITextField * _Nullable x) {
        MJHelper.shared.disableThirdPartyKeyboard = true;
    }];

    [[textField rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(__kindof UITextField * _Nullable x) {
        MJHelper.shared.disableThirdPartyKeyboard = false;
    }];
}

- (UINavigationBarAppearance *)navBarApp  API_AVAILABLE(ios(13.0)){
    if (_navBarApp == nil) {
        _navBarApp = [UINavigationBarAppearance new];
    }
    return _navBarApp;
}

+ (BOOL)isIPhoneX {
    BOOL isIphoneX = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        isIphoneX = NO;
    }
    else if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            isIphoneX = YES;
        }
    }
    return isIphoneX;
}

+ (CGFloat)safeAreaBottom{
    if([self isIPhoneX]){
        return [[[UIApplication sharedApplication] delegate] window].safeAreaInsets.bottom;
    }else{
        return 0;
    }
}

+ (BOOL)isSimuLator{
    if (TARGET_IPHONE_SIMULATOR == 1) {
        //模拟器
        return YES;
    }else{
        //真机
        return NO;
    }
}

+ (BOOL)isDebug {
    BOOL flag = false;
    #if DEBUG
    flag = true;
    #else

    #endif
    
    return flag;

}
@end
